package com.ruoyi.hospital.controller;
import com.ruoyi.common.core.controller.BaseController;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hospital.domain.Hospital;
import com.ruoyi.hospital.service.IHospitalService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import static oshi.software.os.linux.LinuxOperatingSystem.getPageSize;

/**
 * 医院管理Controller
 * 
 * @author 天天困
 * @date 2025-08-14
 */
@RestController
@RequestMapping("/hospital/hospital")
public class HospitalController extends BaseController
{
    @Autowired
    private IHospitalService hospitalService;

    /**
     * 查询医院管理列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospital:list')")
    @GetMapping("/list")
    public TableDataInfo list(Hospital hospital)
    {
        startPage();
        List<Hospital> list = hospitalService.selectHospitalList(hospital);
        return getDataTable(list);
    }

    @GetMapping("/nearby")
    public TableDataInfo nearby(
            @RequestParam double longitude,
            @RequestParam double latitude,
            @RequestParam(required = false, defaultValue = "5") double radius,
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize)
    {
        List<Hospital> list = hospitalService.selectNearbyHospitals(longitude, latitude, radius, pageNum, pageSize);
        return getDataTable(list);
    }






    /**
     * 导出医院管理列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospital:export')")
    @Log(title = "医院管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Hospital hospital)
    {
        List<Hospital> list = hospitalService.selectHospitalList(hospital);
        ExcelUtil<Hospital> util = new ExcelUtil<Hospital>(Hospital.class);
        util.exportExcel(response, list, "医院管理数据");
    }

    /**
     * 获取医院管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospital:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hospitalService.selectHospitalById(id));
    }

    /**
     * 新增医院管理
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospital:add')")
    @Log(title = "医院管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Hospital hospital)
    {
        return toAjax(hospitalService.insertHospital(hospital));
    }

    /**
     * 修改医院管理
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospital:edit')")
    @Log(title = "医院管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Hospital hospital)
    {
        return toAjax(hospitalService.updateHospital(hospital));
    }

    /**
     * 删除医院管理
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospital:remove')")
    @Log(title = "医院管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hospitalService.deleteHospitalByIds(ids));
    }
}
